home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / Powervisor v1.10b disk1.adf / Source / CheckBrackets.c < prev    next >
C/C++ Source or Header  |  1991-09-15  |  1KB  |  60 lines

  1. /* Routine to check brackets on the PowerVisor commandline
  2.  
  3. Compile with :
  4.     lc -v -cmsw -O CheckBrackets
  5.     blink CheckBrackets.o to CheckBrackets lib pv:pvdevelop/lib/PVCallStub.lib
  6. */
  7.  
  8.  
  9. #include <exec/types.h>
  10. #include "pv:PVDevelop/include/PV/screenbase.h"
  11. #include "pv:PVDevelop/include/PV/pvcallroutines.h"
  12. #include <pragmas/exec.h>
  13. #include <string.h>
  14.  
  15. APTR PVCallTable;
  16.  
  17. int __saveds __asm Bracket (register __a0 char *cmdline, register __a2 APTR table[])
  18. {
  19.     char *p,t,o;
  20.     struct StringInfo *si;
  21.     int i,d,l,found;
  22.  
  23.     PVCallTable = table;
  24.  
  25.     p = PVCGetStringGBuf ();
  26.     si = PVCGetStringInfo ();
  27.  
  28.     i = si->BufferPos;
  29.  
  30.     switch (t = p[i])
  31.         {
  32.             case '(' : o = ')'; d= 1; break;
  33.             case ')' : o = '('; d=-1; break;
  34.             case '{' : o = '}'; d= 1; break;
  35.             case '}' : o = '{'; d=-1; break;
  36.             case '[' : o = ']'; d= 1; break;
  37.             case ']' : o = '['; d=-1; break;
  38.             default  : return;
  39.         }
  40.  
  41.     i += d;
  42.     l = 1;
  43.     found = -1;
  44.     while (i >= 0 && i <= si->NumChars)
  45.         {
  46.             if (p[i] == t) l++;
  47.             else if (p[i] == o) l--;
  48.             if (!l)
  49.                 {
  50.                     found = i;
  51.                     i = -2;
  52.                 }
  53.             else i += d;
  54.         }
  55.  
  56.     if (found >= 0) si->BufferPos = found;
  57.  
  58.     PVCRefreshStringG ();
  59. }
  60.